package com.ego.controller;

import com.ego.pojo.Order;
import com.ego.service.OrderService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping
public class OrderController {
    @Resource
    private OrderService orderService;

    @PostMapping("order")
    public ResponseEntity<Long> createOrder(@RequestBody  Order order){
        Long orderId = orderService.save(order);
        return ResponseEntity.ok(orderId);
    }

    @GetMapping("/code/{orderId}")
    public ResponseEntity<String> code(@PathVariable("orderId") Long orderId) {
        return ResponseEntity.ok(orderService.getPayCodeUrl(orderId));
    }

    @GetMapping("/status/{orderId}")
    public ResponseEntity<Integer> queryStatus(@PathVariable("orderId") Long orderId) {
        return ResponseEntity.ok(orderService.getOrderStatus(orderId));
    }
}
